package com.eatwhat.service;

import com.eatwhat.entity.UserChoice;
import com.eatwhat.mapper.UserChoiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;

@Service
public class UserChoiceService {
    
    @Autowired
    private UserChoiceMapper userChoiceMapper;
    
    public void saveUserChoice(String userId, Long foodId) {
        UserChoice userChoice = new UserChoice();
        userChoice.setUserId(userId);
        userChoice.setFoodId(foodId);
        userChoice.setChoiceDate(LocalDate.now());
        userChoiceMapper.insert(userChoice);
    }
    
    public List<UserChoice> getRecentChoices(String userId) {
        return userChoiceMapper.findRecentByUserId(userId);
    }
    
    public List<UserChoice> getTodayChoices(String userId) {
        return userChoiceMapper.findByUserIdAndDate(userId, LocalDate.now());
    }
    
    public List<Object> getPopularFoods(int days) {
        LocalDate endDate = LocalDate.now();
        LocalDate startDate = endDate.minusDays(days);
        return userChoiceMapper.getPopularFoods(startDate, endDate);
    }
}